package com.jianbo.proxy.api;

import org.smartboot.http.server.HttpRequest;

import com.jianbo.proxy.entity.HttpResponseMiddle;
import com.jianbo.proxy.entity.Result;
import com.jianbo.proxy.util.FileUtil;
import com.jianbo.proxy.util.JsonUtil;

public class FileSaveApi extends Api {

    @Override
    public String apiName() {
        return "/editor/fileSave";
    }

    @Override
    public boolean execute(HttpRequest request, HttpResponseMiddle response) throws Exception {
        String filename = request.getParameter("filename");
        String data = request.getParameter("data");
        FileUtil.saveFile(filename, data.getBytes("utf-8"));
        Result<String> result = Result.succeed();
        String json = JsonUtil.toJson(result);
        response.write(json);
        return true;
    }
    
}
